<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>数组扁平化第二种方式</title>
	</head>
	<body>
		<script>
			let arr = [0, [1, [2, 3, [4, [5, 6]], 7]], [8, 9]]

			function flattenArray(arr) {
				return arr.reduce((ans, item) => {
                    //判断是不是数组 如果不是数组就.concat 不然继续循环递归
					return ans.concat(
						Array.isArray(item) ? flattenArray(item) : item
					)
				}, [])
			}

            console.log(flattenArray(arr),"arr")
		</script>
	</body>
</html>
